﻿@using ConfigDashboard.Models
@model ValuesViewModel


@{
    ViewBag.Title = "Values";
}

<h2>Configuration Values</h2>


@Html.ActionLink("Edit Setting Names", "Index", "Settings") | 
@Html.ActionLink("Edit Environments", "Index", "Environments")

@{
    int settingColumnWidth = 300;
    int environmentColumnWidth = 300;
    
    int environmentColumnCount = Model.Environments.Count(); 
    int totalTableWidth = settingColumnWidth + (environmentColumnCount * environmentColumnWidth);
}

<table id="configtable" width="@totalTableWidth">

<colgroup>
 <col width="@settingColumnWidth">
 <col width="@environmentColumnWidth" span="@environmentColumnCount">
</colgroup>
<thead>

<tr>
  <th></th>
@foreach (var env in Model.Environments)
{
  <th>@env.EnvironmentName</th>
}
</tr>

</thead>
<tbody>

@foreach (ConfigSettingValueRow item in Model.Settings)
{
  <tr>
    <th id="@item.SettingName.SettingName" title="@item.SettingName.Comment">@item.SettingName.SettingName</th>

    @foreach (var env in Model.Environments)
    {
        <td>
        @{
            ConfigSettingValue value = null;
            if (item.Values.ContainsKey(env))
            {
                value = item.Values[env];
                <a class="imgbutton" href="@Url.Action("Edit", new { id = item.SettingName.SettingID, env = env.EnvironmentID })" title="Edit"><img src="@Url.Content("~/Images/Edit.png")" alt="" height="16" width="16" border="0"/></a>
                @value.SettingValue
            }
            else
            {
                <a class="imgbutton" href="@Url.Action("Create", new { id = item.SettingName.SettingID, env = env.EnvironmentID })" title="Create"><img src="@Url.Content("~/Images/Add.png")" alt="" height="16" width="16" border="0"/></a>
            }
        }
        </td>
    }
  </tr>
}
</tbody>
</table>
